-- Group B Transmit Team
-- April 9, 2007
-- This file represents a unit that will hold one nibble for doing output to the MII

Library ieee;
Use ieee.std_logic_1164.all;

Entity FrameNibble Is
	Port( MoveInNibble		: In Std_logic_vector(3 downto 0);
		  Clock				: In Std_logic;
		  Move				: In Std_logic;
		  Set 				: In Std_logic;
		  Choose			: In Std_logic_vector(3 downto 0);
		  WriteInNibble0	: In Std_logic_vector(3 downto 0);
		  WriteInNibble1	: In Std_logic_vector(3 downto 0);
		  WriteInNibble2	: In Std_logic_vector(3 downto 0);
		  WriteInNibble3	: In Std_logic_vector(3 downto 0);
		  OutputNibble		: Out Std_logic_vector(3 downto 0);
		  Nibble			: Buffer Std_logic_vector(3 downto 0));
End FrameNibble;

Architecture Behavior Of FrameNibble Is
Constant Zeros : Std_logic_vector(3 downto 0) := "0000";

Begin
	Process
	Begin
		Wait Until Clock'Event And Clock = '1';
		
		If Move = '1' Then
			If Set = '0' Then
				Nibble <= MoveInNibble;
			Else
				If Choose = "0001" Then
					Nibble <= WriteInNibble0;
				Elsif Choose = "0010" Then
					Nibble <= WriteInNibble1;
				Elsif Choose = "0100" Then
					Nibble <= WriteInNibble2;
				Elsif Choose = "1000" Then
					Nibble <= WriteInNibble3;
				End If;
			End If;
		Else
			If Set = '1' Then
				If Choose = "0001" Then
					Nibble <= WriteInNibble0;
				Elsif Choose = "0010" Then
					Nibble <= WriteInNibble1;
				Elsif Choose = "0100" Then
					Nibble <= WriteInNibble2;
				Elsif Choose = "1000" Then
					Nibble <= WriteInNibble3;
				End If;
			End If;
		End If;
		
		OutputNibble <= Nibble;
	End Process;
End Behavior;